$(function () {
    $.ajax({
        url : base + "/manage/getPersonalRecordList.action",
        type : "post",
        data : {},
        cache : false,
        success : function(data) {
            if(data!=null){
                var recordTime = [];
                var T111 = [0,0,0,0,0,0,0];
                var T222 = [0,0,0,0,0,0,0];
                var T333 = [0,0,0,0,0,0,0];
                var T444 = [0,0,0,0,0,0,0];
                var T555 = [0,0,0,0,0,0,0];
                var T666 = [0,0,0,0,0,0,0];
                var T777 = [0,0,0,0,0,0,0];
                var T888 = [0,0,0,0,0,0,0];
                var T999 = [0,0,0,0,0,0,0];
                var k = 0;
                for(var i=0;i<data.rows.length;i++){
                    var flag = true;
                    for(var j=0;j<k;j++) {
                        if (data.rows[i].todayTime==recordTime[j]){
                            flag = false;
                            if(recordTime.length>0){
                                if(data.rows[i].eType==111){
                                    T111[recordTime.length-1]=T111[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==222){
                                    T222[recordTime.length-1]=T222[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==333){
                                    T333[recordTime.length-1]=T333[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==444){
                                    T444[recordTime.length-1]=T444[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==555){
                                    T555[recordTime.length-1]=T555[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==666){
                                    T666[recordTime.length-1]=T666[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==777){
                                    T777[recordTime.length-1]=T777[recordTime.length-1]+data.rows[i].doTime;
                                }else if(data.rows[i].eType==888){
                                    T888[recordTime.length-1]=T888[recordTime.length-1]+data.rows[i].doTime;
                                }else{
                                    T999[recordTime.length-1]=T999[recordTime.length-1]+data.rows[i].doTime;
                                }
                            }

                        }
                    }
                    if(flag){
                        recordTime[k] = data.rows[i].todayTime;
                        k++;
                        if(recordTime.length>0){
                            if(data.rows[i].eType==111){
                                T111[recordTime.length-1]=T111[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==222){
                                T222[recordTime.length-1]=T222[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==333){
                                T333[recordTime.length-1]=T333[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==444){
                                T444[recordTime.length-1]=T444[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==555){
                                T555[recordTime.length-1]=T555[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==666){
                                T666[recordTime.length-1]=T666[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==777){
                                T777[recordTime.length-1]=T777[recordTime.length-1]+data.rows[i].doTime;
                            }else if(data.rows[i].eType==888){
                                T888[recordTime.length-1]=T888[recordTime.length-1]+data.rows[i].doTime;
                            }else{
                                T999[recordTime.length-1]=T999[recordTime.length-1]+data.rows[i].doTime;
                            }
                        }
                    }

                }
                $('#container').highcharts({

                    chart: {
                        type: 'column'
                    },

                    title: {
                        text: '个人锻炼记录'
                    },

                    xAxis: {
                        categories: recordTime
                    },

                    yAxis: {
                        allowDecimals: false,
                        min: 0,
                        title: {
                            text: '锻炼分钟'
                        }
                    },

                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.x + '</b><br/>' +
                                this.series.name + ': ' + this.y +'分钟'+ '<br/>' +
                                'Total: ' + this.point.stackTotal+'分钟';
                        }
                    },

                    plotOptions: {
                        column: {
                            stacking: 'normal'
                        }
                    },

                    series: [{
                        name: '跑步机',
                        data: T111,
                        stack: 'male'
                    },{
                        name: '划船器',
                        data: T222,
                        stack: 'male'
                    },{
                        name: '肌肉组',
                        data: T333,
                        stack: 'male'
                    },{
                        name: '仰卧器',
                        data: T444,
                        stack: 'male'
                    },{
                        name: '健步车',
                        data: T555,
                        stack: 'male'
                    },{
                        name: '美腰机',
                        data: T666,
                        stack: 'female'
                    },{
                        name: '登梯器',
                        data: T777,
                        stack: 'female'
                    },{
                        name: '引体杆',
                        data: T888,
                        stack: 'female'
                    },{
                        name: '瑜伽球',
                        data: T999,
                        stack: 'female'
                    }]
                })
            }else{
                return false;
            }
        },
        async : false
    })
});
